mem.VirtualMemory(): wrong page size on darwin arm64 #1334
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mem.VirtualMemory()
returns values that are 4x larger/smaller than they should be on darwin arm64.Generally speaking,
unix.Getpagesize()
returns the correct page size on macOS; 4K on Intel Macs and 16K on M1 Macs.However, that is not the unit that
host_statistics()
values are measured in; they are kernel memory pages which arevm_kernel_page_size
bytes long.You can see this in the source code of
vm_stat
, which is the executable that the non-CGO version of the darwin VM stats runs and parses.https://github.com/unofficial-opensource-apple/system_cmds/blob/master/vm_stat.tproj/vm_stat.c#L126-L132
This PR replaces
unix.Getpagesize()
withC.vm_kernel_page_size